home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 883 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.6 KB  |  52 lines

  1. Path: lasernet.com!jonathan_wooldridge
  2. Newsgroups: comp.lang.c++
  3. Message-ID: <60107174041$71C7@lasernet.com>
  4. X-Gateway: Act-Up 4.6  07 Jan 96 17:40:41  LaserNet, Serving Fido style systems
  5. Date: Sun, 7 Jan 96 14:34:04 LOC
  6. Organization: 1BBS ■ Imperial Beach CA ■ 619∙429∙6521/6123 ■ (52:1000/153)
  7. From: Jonathan Wooldridge <jonathan_wooldridge@lasernet.com>
  8. In-Reply-To: Bret Bieghler
  9. Subject: Global Variables in GUI
  10.  
  11. -=> Quoting Bret Bieghler to All <=-
  12.  BB> Many people think that global variables are the children of Satan,
  13.  BB> but here is a case where I'm not sure what to do.
  14.  
  15. Hi Bret! Here's two ideas on this:
  16.  
  17. 1). If several objects need access to the same data, the cleanest way might
  18.     be to have them all be of the same class (or have them all be subclassed
  19.     off the same class) then include a static data item, and manipulators.
  20.  
  21. class CParent {
  22. protected:
  23.     static int status
  24.     int SetStatus(int s);
  25. }
  26. class foo : public CParent {
  27.     /* whatever your current class is */
  28. }
  29.     NOTE: be sure to declare static data items, just like you declare
  30.     functions, in the code section, as they are effectively global in scope.
  31.  
  32. 2). You might also try creating a global scope class object, CGlobal,
  33.     that contains protected manipulator items. Then, any classes
  34.     that will need to access the data/manipulator funcs could be declared
  35.     as friends to the CGlobal object.
  36.  
  37. class CGlobal {
  38. friend foo;               // foo, and any other classes that will SetStatus
  39. protected:
  40.     int SetStatus(int s);
  41. private:
  42.     int status;
  43. };
  44.  
  45. It's a thought. Happy Hunting!
  46.  
  47.                  -SpyroGyra
  48. ---
  49.  ■ TLX v4.00 ■ A drunken man's words are a sober man's thoughts.
  50.  
  51. ---
  52.